package com.sky.mapper;
import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.sky.anotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper extends BaseMapper<Dish> {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @Override
    @AutoFill(OperationType.INSERT)
    int insert(Dish entity);



   Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);


    int delById(@Param("id") Long id);

   Dish selectById(Long id);


   @AutoFill(OperationType.UPDATE)
   void updateDish(Dish dish);


  List<Dish> selectDishByCategoryId(Dish dish);


@Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
List<Dish> getBySetmealId(Long setmealId);

/**
 * 根据条件统计菜品数量
 * @param map
 * @return
 */
Integer countByMap(Map map);
}
